﻿using Ledict.ConditionExtract.Model;
using Ledict.Core.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ledict.ConditionExtract.DAL
{
    public class ElementExtractSourceDAL
    {
        private string DbName;
        public ElementExtractSourceDAL()
        {
            DbName = "LdtCommonManage";
        }

        /// <summary>
        /// 增加ElementExtractSource表数据
        /// </summary>
        public bool ElementExtractSourceAdd(ElementExtractSource model)
        {
            string sql = string.Format(@" insert into dbo.ElementExtractSource(EES_ID,EES_Code,EES_CodeCH,EES_SourceName,EES_ParagraphName,EES_SourceType,EES_ElementType,EES_ElementPath,EES_Where,EES_Remark,EES_UpdateTime,IsML) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}') ",
                model.EES_ID, model.EES_Code, model.EES_CodeCH, model.EES_SourceName, model.EES_ParagraphName, model.EES_SourceType, model.EES_ElementType,model.EES_ElementPath,model.EES_Where,model.EES_Remark,DateTime.Now,model.EES_IsML);
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(sql);   
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 删除ElementExtractSource表数据
        /// </summary>
        public bool ElementExtractSourceDelete(string eesId)
        {
            string sql = string.Format(@" delete from ElementExtractSource where EES_ID='{0}' ", eesId);
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(sql);
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 修改ElementExtractSource表数据
        /// </summary>
        public bool ElementExtractSourceUpdate(ElementExtractSource model)
        {
            string sql = string.Format(@" update ElementExtractSource set EES_Code='{0}',EES_CodeCH='{1}',EES_SourceName='{2}',EES_ParagraphName='{3}',EES_SourceType='{4}',EES_ElementType='{5}',EES_ElementPath='{6}',EES_Where='{7}',EES_Remark='{8}',EES_UpdateTime='{9}',IsML='{11}' where EES_ID='{10}' ",
               model.EES_Code, model.EES_CodeCH, model.EES_SourceName, model.EES_ParagraphName, model.EES_SourceType, model.EES_ElementType, model.EES_ElementPath, model.EES_Where, model.EES_Remark, DateTime.Now, model.EES_ID,model.EES_IsML);
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(sql);          
            if (oBase.ExecuteNonQuery(oCmd) > 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 获取ElementExtractSource表数据
        /// </summary>
        public DataTable GetElementExtractSourceData(string eesId)
        {
            string strSql = string.Format(@" select * from ElementExtractSource where EES_ID ='{0}'  ", eesId);
            Database oBase = DatabaseFactory.CreateDatabase(DbName);
            DbCommand oCmd = oBase.GetSqlStringCommand(strSql.ToString());
            DataTable dt = oBase.ExecuteDataSet(oCmd).Tables[0];
            if (dt != null && dt.Rows.Count > 0)
            {
                return dt;
            }
            return new DataTable();
        }
    }
}
